Device
The Device namespace provides access to information about the current device and its environment, including hardware characteristics, system details, screen metrics, battery status, orientation, proximity sensor state, locale and language settings, wake lock control, and network interfaces.
This API is commonly used to adapt UI layouts, behavior, and feature availability based on the device’s runtime context.
Orientation
Represents the physical orientation of the device.
Description
portrait: Portrait orientation, default upright positionportraitUpsideDown: Portrait orientation, upside downlandscapeLeft: Landscape orientation rotated to the leftlandscapeRight: Landscape orientation rotated to the rightfaceUp: Device is lying flat with the screen facing upwardfaceDown: Device is lying flat with the screen facing downwardunknown: Orientation cannot be determined
NetworkInterface
Describes a single network interface address.
Properties
address: IP addressnetmask: Subnet maskfamily: Address family, either IPv4 or IPv6mac: MAC address (may be null depending on system restrictions)isInternal: Indicates whether the interface is internal (for example, loopback)cidr: CIDR notation, such as192.168.1.10/24
BatteryState
Represents the current battery state.
Description
full: Battery is fully chargedcharging: Device is currently chargingunplugged: Device is not connected to powerunknown: Battery state cannot be determined
Device Information
model
The device model, such as "iPhone" or "iPad".
localizedModel
The localized name of the device model.
systemVersion
The current operating system version, for example "18.2".
systemName
The name of the operating system, such as "iOS", "iPadOS", or "macOS".
isiPad / isiPhone
Indicates whether the current device is an iPad or an iPhone.
screen
Screen metrics:
width: Screen width in logical pixelsheight: Screen height in logical pixelsscale: Screen scale factor (for example, 2 or 3)
Battery and Sensors
batteryState
The current battery state.
batteryLevel
The current battery level, expressed as a value between 0.0 and 1.0.
proximityState
The state of the proximity sensor.
true indicates that the device is close to the user, such as during a phone call.
Orientation and Layout
isLandscape / isPortrait / isFlat
isLandscape: Indicates whether the device is in a landscape orientationisPortrait: Indicates whether the device is in a portrait orientationisFlat: Indicates whether the device is lying flat (face up or face down)
orientation
The current physical orientation of the device.
Appearance and Environment
colorScheme
The current system color scheme, such as light or dark mode.
isiOSAppOnMac
Indicates whether the current process is an iPhone or iPad app running on macOS.
Locale and Language
systemLocale
The current system locale, for example "en_US".
preferredLanguages
The user’s preferred languages, for example:
systemLocales (Deprecated)
Deprecated. Use preferredLanguages instead.
systemLanguageTag
The current language tag, such as "en-US".
systemLanguageCode
The current language code, such as "en".
systemCountryCode
The current country code, such as "US".
systemScriptCode
The script code of the current locale, such as "Hans" for Simplified Chinese.
Wake Lock
isWakeLockEnabled
Retrieves whether the wake lock is currently enabled, preventing the device from automatically sleeping.
setWakeLockEnabled
Enables or disables the wake lock.
Notes:
- Available only in the Scripting app
- When enabled, the device will remain awake and not auto-lock
Battery Listeners
addBatteryStateListener
Registers a listener for battery state changes.
removeBatteryStateListener
Removes a battery state listener.
If callback is not provided, all battery state listeners are removed.
addBatteryLevelListener
Registers a listener for battery level changes.
removeBatteryLevelListener
Removes a battery level listener.
If callback is not provided, all battery level listeners are removed.
Orientation Listeners
addOrientationListener
Starts observing device orientation changes.
Notes:
- This method must be called before orientation updates are delivered
- Orientation updates do not work when system orientation lock is enabled
removeOrientationListener
Removes an orientation change listener.
If callback is not provided, all orientation listeners are removed and observation is stopped.
Proximity Listeners
addProximityStateListener
Registers a listener for proximity sensor state changes.
removeProximityStateListener
Removes a proximity state listener.
If callback is not provided, all proximity listeners are removed.
Network
networkInterfaces
Returns the network interfaces available on the device.
Return value:
- Keys are interface names (such as
en0,lo0) - Values are arrays of
NetworkInterfaceobjects associated with each interface
This method is useful for network diagnostics, retrieving local IP addresses, and debugging connectivity issues.
